/*
ID: brodyzt1
PROG: milk
LANG: C++
*/

#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <sstream>
#include <fstream>

using namespace std;

int main(int argc, const char * argv[])
{
    ifstream input("milk.in");
    int wantedMilk, numFarmers;
    input >> wantedMilk >> numFarmers;
    vector<int> amountCharged (numFarmers, 0), amountSelling (numFarmers, 0);
    ofstream output("milk.out");
    for (int i =  0; i < numFarmers; i++) {
        input >> amountCharged[i] >> amountSelling[i];
    }
    
    int tempInt = 0;
    
    for (int i = 0; i < numFarmers; i++) {
        for (int j = 0; j < numFarmers - 1; j++) {
            if (amountCharged[j] > amountCharged[j+1]) {
                tempInt = amountCharged[j];
                amountCharged[j] = amountCharged[j+1];
                amountCharged[j+1] = tempInt;
                
                tempInt = amountSelling[j];
                amountSelling[j] = amountSelling[j+1];
                amountSelling[j+1] = tempInt;
            }
        }
    }
    int milkCollected = 0, totalCost = 0;
    tempInt = 0;
    while (milkCollected != wantedMilk) {
        if (milkCollected + amountSelling[tempInt] <= wantedMilk) {
            milkCollected += amountSelling[tempInt];
            totalCost += amountSelling[tempInt] * amountCharged[tempInt];
        } else {
            totalCost += (wantedMilk - milkCollected) * amountCharged[tempInt];
            milkCollected = wantedMilk;
        }
         tempInt++;
    }
    output << totalCost << "\n";
    input.close();
    output.close();
    
    return 0;
}

